// pages/index/discussion/discussiondetails/discussiondetails.js
import Dialog from "../../../../miniprogram_npm/@vant/weapp/dialog/dialog"
import Toast from "../../../../miniprogram_npm/@vant/weapp/toast/toast"

const app = getApp()
const log = new app.appLogs()
const http = new app.appHttp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        url: "",
        id: "",
        details: "",
        paginationList: "",
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            id: options.id,
            url: app.globalData.url
        })
        this.getDetails()
        this.getPage_view()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getPaginationList()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    getDetails: function (e) {
        const than = this
        http.get("bouleuterion/details", {
            id: than.data.id
        }).then(res => {
            if (res.data.code == 200) {
                res.data.data.content = res.data.data.content
                    .replace(/<img/gi, '<img style="max-width:100%;height:auto;float:left;display:block" ')
                    .replace(/<section/g, '<div')
                    .replace(/\/section>/g, '\div>');
                than.setData({
                    details: res.data.data
                })
            }
        })
    },
    getPaginationList: function (e) {
        const than = this
        http.get("bouleuterion_message/pagination", {
            bouleuterion_id: than.data.id,
            page_number: 1,
            page_size: 1000,
        }).then(res => {
            if (res.data.code == 200) {
                than.setData({
                    paginationList: res.data.data.list
                })
                log.e(than.data.paginationList.length)
            }
        })
    },
    getPage_view: function (e) {
        const than = this
        http.put("bouleuterion/page_view", {
            id: than.data.id,
        }).then(res => {
            log.e(JSON.stringify(res))
        })
    },
    /**
     * 留言
     * @param e
     */
    getMessage:function (e){
        const than=this
        wx.navigateTo({
          url: '../message/message?id='+than.data.id,
        })
    }
})